package com.designpattern.secondchapter.one;

import java.util.ArrayList;

public class WeatherData implements Subject{
	
	private ArrayList<Observer> arrayList;
	private float temp;
	private float humidity;
	private float presure;
	public WeatherData() {
		arrayList = new ArrayList<>();
		
	}
	
	@Override
	public void registerOberver(Observer o) {
		if (o != null) {
			arrayList.add(o);
		}
	}

	@Override
	public void removeObserver(Observer o) {
		int index = arrayList.indexOf(o);
		arrayList.remove(index);
		
	}

	@Override
	public void notifyObservers() {
		for (Observer o : arrayList) {
			o.update(temp, humidity, presure);
		}
	}
	
	public void measurementsChanged() {
		notifyObservers();
	}
	
	public void setMeasurements(float temp, float humidity, float presure) {
		this.temp = temp;
		this.humidity = humidity;
		this.presure = presure;
		measurementsChanged();
		
	}

}
